﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DataAccess;
namespace SQT.tracnghiem.Ajax.ASP.Lesson
{
    public partial class upload_snd_Word : System.Web.UI.Page
    {
        public const string PATH_UPLOAD_au = "~/Content/testdata/audio/";
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = int.Parse(Request.QueryString["id"]);
            HttpPostedFile file = Request.Files[0];
            string[] temp = new string[file.FileName.Split('.').Length];
            temp = file.FileName.Split('.');
            string temp2 = Session["admin_id"].ToString() + "_" + DateTime.Now.Day.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Year.ToString() + DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString();
            temp2 += file.FileName;

            file.SaveAs(Server.MapPath(PATH_UPLOAD_au) + "/" + temp2);
            var get_file = new TblLessonWordFileController().FetchAll().Where(x => x.FileLessonId == id).ToList();
            if (get_file.Count != 0)
                new TblLessonWordFileController().Update(get_file[0].FileId, temp2, null);
            else
                new TblLessonWordFileController().Insert(temp2, id);

        }
    }
}